import type { Data, TableDataInfo } from '@/types/global'
import type { DonationVo } from '@/types/home'
import { http } from '@/utils/http'
/**
 *
 * @param id 根据id查询捐赠物详情
 * @returns
 */
export const getDonationByIdAPI = (id: number) => {
  return http<Data<DonationVo>>({
    url: `/donation/${id}`,
    method: 'GET',
  })
}

/**
 *
 * @param data 订单取消
 * @returns
 */
export const putCancelOrder = (data: { id: number; cancelReason: string }) => {
  return http<Data<number>>({
    url: `/user/cancelOrder`,
    method: 'PUT',
    data,
  })
}

/**
 *
 * @param id 收藏
 * @returns
 */
export const postAddCollectionAPI = (id: number) => {
  return http<Data<number>>({
    url: `/donation/addCollection/${id}`,
    method: 'POST',
  })
}

/**
 *
 * @param id 取消收藏
 * @returns
 */
export const deleteCollectionAPI = (id: number) => {
  return http<Data<number>>({
    url: `/user/deleteCollection/${id}`,
    method: 'DELETE',
  })
}

/**
 *
 * @returns 查询收藏列表
 */
export const getCollectionListAPI = () => {
  return http<TableDataInfo<DonationVo[]>>({
    url: `/user/collectDonationVoList`,
    method: 'GET',
  })
}

/**
 * 用户预取货-锁定捐赠物
 * @param id
 * @returns
 */
export const putLockDonationAPI = (id: number) => {
  return http<Data<number>>({
    url: `/user/lockDonation/${id}`,
    method: 'PUT',
  })
}
